<!-- 
	只显示 区域及各省，没有各县级市及区
 -->
<template>
	<view class="diquPopup">
		<view class="area-title">您的业务地区</view>
		<view class="area-desc">选择合适您的业务地区</view>
		<scroll-view class="area-box" scroll-y="true">
			<view class="area-item">
				<view class="area-fenbu">
					全国
				</view>
				<view class="area-name">
					<view :class="{active:memoryDiquArr[0]===''}" @click="clickDiqu('')">全国</view>
				</view>
			</view>
			<view class="area-item" v-for="(item,index) in areas['qy']" :key="index">
				<view class="area-fenbu">
					{{item.v}}
				</view>
				<view class="area-name">
					<view v-for="(x,index) in areas[item.k]" :key="index" @click="clickDiqu(x.k)"
						:class="{active:memoryDiquArr.indexOf(x.k)!==-1}">
						{{x.v}}
					</view>
				</view>
			</view>
		</scroll-view>

		<view class="filter-foot d-f">
			<view class="cancel-btn" @click="areaReset()">
				<image src="https://img.bidcenter.com.cn/uni/chongzhi.png" class="chongzhiIcon"></image>重置
			</view>
			<view class="confirm-btn" @click="confirm">确定</view>
		</view>

	</view>
</template>

<script>
	import {
		areas,
		areaMap
	} from '@/util/diction.js';
	export default {
		name: "diqu-member",
		// 'isyhqReturn',
		// ,'fanhui''selectPrice',
		props: ['initDiqu', 'areaPop', "maxnum"],
		data() {
			return {
				areas: areas,
				memoryDiquArr: this.$props.initDiqu,
				// memoryMaxnum: this.$props.maxnum
			};
		},
		watch: {
			initDiqu(a, b) {
				this.memoryDiquArr = a;
				// 交互：最多选择maxnum个超过六个则选择全国,maxnum改为变量，
				if (this.maxnum > 0 && this.memoryDiquArr.length >= this.maxnum) {
					this.memoryDiquArr = ['']
				}
			},
		},
		mounted() {},
		methods: {
			// 地区重置
			areaReset() {
				this.memoryDiquArr = ['']

			},
			clickDiqu(k) {
				// 全国
				if (k === '') {

					if (this.memoryDiquArr.indexOf(k) !== -1) {
						this.memoryDiquArr = []
					} else {
						this.memoryDiquArr = ['']
					}

				} else {
					// 非全国
					// 如选中全国，先移除掉
					if (this.memoryDiquArr.indexOf('') !== -1) {
						this.memoryDiquArr = this.memoryDiquArr = this.memoryDiquArr.filter(item => item !== '')
					}

					if (this.memoryDiquArr.indexOf(k) !== -1) {
						this.memoryDiquArr = this.memoryDiquArr.filter(item => item !== k)
					} else {
						this.memoryDiquArr.push(k)
						// 交互：最多选择maxnum个超过六个则选择全国,maxnum改为变量，
						if (((this.memoryDiquArr.length >= this.maxnum) && this.maxnum !== -1) || this.maxnum === -1) {
						
							this.memoryDiquArr = ['']
						}
					}
				}
			},
			confirm() {
				if (!this.memoryDiquArr.length) {
					this.memoryDiquArr = ['']
				}
				this.$emit("update:initDiqu", this.memoryDiquArr);
				// this.$emit("update:selectPrice", this.selectPrice);
				// this.$emit("update:isyhqReturn", 1);
				// this.$emit("update:fanhui", 0);
				this.$emit("update:areaPop", false)
				
				this.$emit('loadJiage',false,true)
			},
			areaReset() {
				this.memoryDiquArr = ['']
			}
		},
	}
</script>

<style lang="scss">
	@import '@/static/css/diqu.scss';
</style>